﻿using Milvus.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace RagSharpCore.Service
{
	public static class SearchResultsExtension
	{
		public static SearchResultItem CastToItem(this SearchResults searchResults)
		{

			string jsonBody = JsonSerializer.Serialize(searchResults, new JsonSerializerOptions
			{
				PropertyNamingPolicy = JsonNamingPolicy.CamelCase  // 匹配JSON的驼峰命名
			});
			var searchResultItem = JsonSerializer.Deserialize<SearchResultItem>(
				jsonBody,
				new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }
			);
			return searchResultItem;
		}



		public static Dictionary<string, IList<string>> CastToDict(this SearchResults searchResults)
		{
			var dict = new Dictionary<string, IList<string>>();
			foreach (var fieldData in searchResults.FieldsData)
			{
				string fieldName = fieldData.FieldName; 
				var objs = fieldData.GetData().CastTo<string>(fieldData.DataType);
				dict.Add(fieldName, objs);
			}
			return dict;
		}
	}
}
